package com.example.myapplication.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import androidx.fragment.app.Fragment;
import com.example.myapplication.R;
import com.example.myapplication.util.ImageUrls;
import com.squareup.picasso.Picasso;

/**
 * A simple {@link Fragment} subclass.
 */
public class f8 extends Fragment {
    View view;
    Context context;
    private GridView f8Gridview;

    F8ItemAdapter adapter;

    public f8() {
        // Required empty public constructor
    }

    int j;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_f8, container, false);
        context = getContext();
        f8Gridview = (GridView) view.findViewById(R.id.f8_gridview);
        ImageView targetImageView3 = (ImageView) view.findViewById(R.id.imageview3);
            String[] mDatas = ImageUrls.imageurls;
            adapter = new F8ItemAdapter(context, mDatas);
            f8Gridview.setAdapter(adapter);
            return view;
        }

    class F8ItemAdapter extends BaseAdapter {

        String[]mDatas;
        private Context context;
        private LayoutInflater layoutInflater;

        public F8ItemAdapter(Context context,String[]mDatas) {
            this.mDatas=mDatas;
            this.context = context;
            this.layoutInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            return mDatas.length;
        }

        @Override
        public Object getItem(int position) {
            return mDatas[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;

            if (convertView == null) {
                convertView = layoutInflater.inflate(R.layout.f8_item, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            String url=mDatas[position];

            Picasso.get().load(url).into(holder.f8Image);
            return convertView;
        }

        protected class ViewHolder {
            private ImageView f8Image;
            public ViewHolder(View view){
                f8Image = (ImageView) view.findViewById(R.id.f8_image);
            }
        }
    }
}